/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package camel.server.admin;

import java.io.Serializable;
import java.util.Date;
import java.util.logging.Logger;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import static javax.persistence.TemporalType.TIMESTAMP;

/**
 *
 * @author mac
 */
@Entity
@NamedQueries ( {
	@NamedQuery(name = "findAllTeamMembers", query = "SELECT t FROM TeamMember t"),
	@NamedQuery(name = "findAllOnlineTeamMembers", query = "SELECT t FROM TeamMember t WHERE loginState = :online AND memberRole <> :not_role")
})
public class TeamMember implements Serializable {
    private static final long serialVersionUID = 1L;

    private static final Logger logger = Logger.getLogger(
                "camel.server.admin.TeamMember");
    
    @Id
    private String id;
    private String password;
    private String contact1;
    private String contact2;

    public enum LoginState { offline, online };
    private LoginState loginState = LoginState.offline;
    
    public enum MemberRole { disabled, user, admin };
    private MemberRole memberRole = MemberRole.user;
        
    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TeamMember)) {
            return false;
        }
        TeamMember other = (TeamMember) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "camel.server.admin.TeamMember[id=" + id + "]";
    }
    
    
    public MemberRole getMemberRole() {
        return memberRole;
    }

    public void setMemberRole(MemberRole memberRole) {
        this.memberRole = memberRole;
    }

    public Boolean IsPasswordMatch(String password) {
        logger.info(new String("IsPasswordMatch : " + password));
        String hash = new String("NEED_HASH_") + password;
        logger.info(new String("IsPasswordMatch (hashed): " + hash));
        return hash.equals(this.password);
    }
    public String getPassword() {
    	return password;
    }
    public void setPassword(String password) {
        this.password = "NEED_HASH_" + password;
    }

    public String getContact1() {
        return contact1;
    }

    public void setContact1(String contact1) {
        this.contact1 = contact1;
    }

    public String getContact2() {
        return contact2;
    }

    public void setContact2(String contact2) {
        this.contact2 = contact2;
    }

    public LoginState getLoginState() {
        return loginState;
    }

    public void setLoginState(LoginState loginState) {
        this.loginState = loginState;
    }

}
